﻿

app.controller("OHSController", function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.GetOHSCheckList = function (year) {
        $scope.CheckList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetCheckRecordList',
            data: { 'year': year }
        })
            .success(function (ret) {
                $scope.CheckList = ret.Data;

            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetDepartmentList = function () {
        $scope.DepartmentList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetDepartmentList',
        })
            .success(function (ret) {
                $scope.DepartmentList = ret.Data;

            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.GetWSCheckYearList = function () {
        $scope.YearList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetWSCheckYearList',
        })
            .success(function (ret) {
                $scope.YearList = ret.Data;

            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.GetWorkPlaceList = function (id) {
        if (id == null || id == '') {
            return false;
        }get
        $scope.WorkPlaceList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetWorkPlaceList',
            data: { 'DepartmentId': id }
        })
            .success(function (ret) {
                $scope.WorkPlaceList = ret.Data;
            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.ExportEmployeeList = function () {
        $scope.DataLoading = true;

        location.href = 

        $scope.DataLoading = false;
    }

    $scope.GetAllWorkPlaceList = function () {
        $scope.WorkSpaceList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetAllWorkPlaceList',
        })
            .success(function (ret) {
                $scope.WorkSpaceList = ret.Data;
            })
            .error(function (data, status, headers, config) {

            });
    }
    $scope.GetAllHarmList = function (control, defaultvalue) {
        $scope.HarmList = [];
        $("#" + control).empty();
        $http({
            method: 'POST',
            url: '../OHS/GetAllHarmList',
        })
            .success(function (ret) {
                $scope.HarmList = ret.Data;
                $.each(ret.Data, function (i, n) {

                    if (defaultvalue != null && defaultvalue.length > 0) {
                        if (defaultvalue.includes(n.Id))
                            $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.HarmfulFactor + "</option>")($scope));
                        else
                            $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.HarmfulFactor + "</option>")($scope));
                    }
                    else {
                        $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.HarmfulFactor + "</option>")($scope));
                    }

                })
                $("#" + control).selectpicker('refresh');
            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.ImportEmployeeList = function () {
        $scope.DataLoading = true;
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../OHS/EmployeeImportFromExcel',
            file: files
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.ResultMsg = ret.Data;
                    alertify.alert("员工数据导入成功！");

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                common.error($scope);
            })
    }

    $scope.ModifyEmployee = function (model, searchmodel, page) {

        var harm = $("#select_Harm").val();
        $http({
            method: 'POST',
            url: '../OHS/EditEmployee',
            data: { "model": model, "HarmList": harm }
        })
            .success(function (ret) {
                if (ret.Code == 100) {
                    alertify.alert("修改成功！");
                    document.getElementById("btn_close").click();
                    $scope.GetEmployeePageList(searchmodel, page);
                }
            })
            .error(function (data, status, headers, config) {

            });

    }

    $scope.ImportWorkShopCheckRecord = function () {
        $scope.DataLoading = true;
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../OHS/ImportWorkSpaceCheckRecord',
            file: files
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert("场所检测数据导入成功！");

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                common.error($scope);
            })
    }

    $scope.ImportCheckRecordList = function () {
        $scope.DataLoading = true;
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../OHS/ImportCheckRecord',
            file: files
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert("体检数据导入成功！");

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                common.error($scope);
            })
    }
    $scope.ImportOHSDevice = function () {
        $scope.DataLoading = true;
        var files = document.querySelector('input[type=file]').files;
        Upload.upload({
            method: 'POST',
            url: '../OHS/ImportOHSDevice',
            file: files
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert("设备数据导入成功！");

                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
                common.error($scope);
            })
    }
    $scope.GetEmployeePageList = function (model, page) {
        $scope.DataLoading = true;
        model.HarmId = $("#search_Harm").val();
        $http({
            method: 'POST',
            url: '../OHS/GetEmployeePageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                common.success($scope, null, ret);
                $scope.EmployeeList = ret.Data.Data;
                $scope.TotalCount = ret.Data.TotalItemCount;

            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
            });
    }
    $scope.ExportEmployeePageList = function (model, page) {
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在导出";
        $http({
            method: 'POST',
            url: '../OHS/ExportEmployeePageList',
            data: { 'model': model}
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                $scope.LoadingMsg = "正在加载";
                if (ret.Code == 100) {
                    window.location.href = ret.Data;
                }
                else {
                    alertify.alert("数据导出失败！");
                }

            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.GetCheckRecordPageList = function (model, page) {
        $scope.DataLoading = true;
        model.HarmId = $("#search_Harm").val();
        $scope.CheckRecordList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetCheckFormPageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                common.success($scope, null, ret);
                $scope.CheckRecordList = ret.Data.Data;
                $scope.TotalCount = ret.Data.TotalItemCount;
            })
            .error(function (data, status, headers, config) {
                $scope.DataLoading = false;
            });
    }
    $scope.GetWSCheckRecordPageList = function (model, page) {
        $scope.DataLoading = true;
        var hlist = $("#select_Harm").val();
        model.HarmId = hlist;
        $scope.CheckRecordList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetWorkPlaceCheckRecordPagelist',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                common.success($scope, null, ret);
                $scope.CheckRecordList = ret.Data.Data;
                $scope.TotalCount = ret.Data.TotalItemCount;
            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.GetOHSDevicePageList = function (model, page) {
        $scope.DataLoading = true;
        $scope.DevicePageList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetOHSDevicePageList',
            data: { 'model': model, 'page': page }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                common.success($scope, null, ret);
                $scope.DevicePageList = ret.Data.Data;
                $scope.TotalCount = ret.Data.TotalItemCount;
            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.GetResultTypeList = function () {
        $scope.ResultTypeList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetResultTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.ResultTypeList = ret.Data;
            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetCheckTypeList = function () {
        $scope.CheckTypeList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetCheckTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.CheckTypeList = ret.Data;
            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.ShowCheckRecordDetail = function (model) {
        var tempmodel = JSON.parse(JSON.stringify(model))
        $scope.RecordDetail = tempmodel;
        $scope.RecordDetail.CheckTypeId = $scope.RecordDetail.CheckTypeId + '';
        $scope.RecordDetail.CheckDate = $filter('JSONDate')($scope.RecordDetail.CheckDate, 'yyyy-MM-dd');
        $scope.RecordDetail.CreateTime = $filter('JSONDate')($scope.RecordDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
        $scope.GetAllHarmList('select_Harm', $scope.RecordDetail.HarmIdList);
    }
    $scope.ShowWSCheckRecordDetail = function (model) {
        var tempmodel = JSON.parse(JSON.stringify(model))
        $scope.RecordDetail = tempmodel;
        $scope.RecordDetail.CreateTime = $filter('JSONDate')($scope.RecordDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');
        var harmlist = [];
        harmlist.push($scope.RecordDetail.HarmId);
        $scope.GetAllHarmList('edit_Harm', harmlist);
        console.log($scope.RecordDetail);
    }
    $scope.ShowEmployeeDetail = function (model) {
        var tempmodel = JSON.parse(JSON.stringify(model))
        $scope.EmployeeDetail = tempmodel;
        $scope.GetAllHarmList('select_Harm', $scope.EmployeeDetail.HarmIdList);
        $scope.EmployeeDetail.DepartmentId = $scope.EmployeeDetail.DepartmentId + '';
        $scope.EmployeeDetail.WorkSpaceId = $scope.EmployeeDetail.WorkSpaceId + '';
        $scope.EmployeeDetail.StartTime = $filter('JSONDate')($scope.EmployeeDetail.StartTime, 'yyyy-MM-dd');
        $scope.EmployeeDetail.EndTime = $filter('JSONDate')($scope.EmployeeDetail.EndTime, 'yyyy-MM-dd');
        $scope.EmployeeDetail.CreateTime = $filter('JSONDate')($scope.EmployeeDetail.CreateTime, 'yyyy-MM-dd HH:mm:ss');

    }

    $scope.DeleteCheckRecord = function (model, page, searchmodel) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认删除【" + model.EmployeeInfo.EmployeeName + model.CheckYear + "年】体检数据？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../OHS/DeleteCheckRecord',
                    data: { 'model': model, 'page': page }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            $scope.GetCheckRecordPageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.DeleteWSCheckForm = function (model, page, searchmodel) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认删除【" + model.WorkSpaceName + model.Years + "年" + model.HarmFactor+"】检查记录？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../OHS/DeleteWSCheckForm',
                    data: { 'Id': model.Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            $scope.GetWSCheckRecordPageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.DeleteDevice = function (Id, page, searchmodel) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认删除该设备？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../OHS/DeleteDevice',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            $scope.GetOHSDevicePageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }

    $scope.GetUserPageList = function (searchmodel, page) {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetUserPageList',
            data: { 'model': searchmodel },
            params: { 'page': page }
        }).success(function (ret) {
            $scope.PageLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }
    $scope.BindDepartmentList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SystemConfig/GetDepartmentList'
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $("#" + control);
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (n.Id == defaultvalue)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.BindDepartmentsList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $("#" + control).empty();
        $http({
            method: 'POST',
            url: '../SystemConfig/GetDepartmentList'
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $("#" + control);
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (defaultvalue.includes(n.Id))
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.BindWorkSpacesList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $("#" + control).empty();
        $http({
            method: 'POST',
            url: '../OHS/GetAllWorkPlaceList',
        })
            .success(function (ret) {
                $scope.PageLoading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $("#" + control);
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (defaultvalue.includes(n.Id))
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.WorkSpaceName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.WorkSpaceName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.WorkSpaceName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DisableDevice = function (Id, Status, page, searchmodel) {
        var str = "";
        if (Status == 0) {
            str = "停用";
        }
        else {
            str = "启用";
        }
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认" + str + "该设备？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../OHS/DisableDevice',
                    data: { 'Id': Id, 'Status': Status }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            $scope.GetOHSDevicePageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }

    $scope.DisableEmployee = function (Id, Status, page, searchmodel) {
        var str = "";
        if (Status == 0) {
            str = "禁用";
        }
        else {
            str = "启用";
        }
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认" + str + "该员工？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../OHS/DisableEmployee',
                    data: { 'Id': Id, 'Status': Status }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            $scope.GetEmployeePageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }

    $scope.EditCheckRecord = function (model, page, searchmodel) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();

                var harm = $("#select_Harm").val();

                $http({
                    method: 'POST',
                    url: '../OHS/EditCheckRecord',
                    data: { 'model': model, 'HarmList': harm }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            document.getElementById("btn_close").click();
                            $scope.GetCheckRecordPageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.EditCheckRecord = function (model, page, searchmodel) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();

                model.HarmId = $("#edit_Harm").val();
                model.Result = $("#edit_result").val();
                console.log(model);
                $http({
                    method: 'POST',
                    url: '../OHS/EditWSCheckForm',
                    data: { 'model': model}
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            alertify.alert("操作成功！");
                            document.getElementById("btn_close").click();
                            $scope.GetWSCheckRecordPageList(searchmodel, page);
                        } else
                            alertify.alert(ret.Msg);

                    })
                    .error(function (data, status, headers, config) {
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }
    $scope.LoadDataAnalysis = function () {
        $scope.LoadingMsg = "正在加载...";
        $scope.DataLoading = true;
        $scope.GetRetireEmployeeList();
        $scope.GetNeedCheckEmployee();
        $scope.GetReCheckEmployee();
        $scope.GetYearsReCheckEmployee();

        $scope.GetCheckYearsCount();
        $scope.GetCheckResultChart();
        $scope.GetCheckTypeChart();
        $scope.GetCheckRateChart();
    }

    $scope.GetRetireEmployeeList = function () {
        $scope.RetireCount = 0;
        $http({
            method: 'POST',
            url: '../OHS/GetRetireEmployee'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.RetireCount = ret.Data.length;
                    $scope.RetireList = ret.Data;
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.ExportRetireList = function () {
        $scope.YearCheckCount = 0;
        $http({
            method: 'POST',
            url: '../OHS/ExportRetireList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    //$scope.YearCheckCount = ret.Data;
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }
    $scope.ShowCheckWin = function (list) {
        $scope.EmployeeList = list;
    }

    $scope.GetNeedCheckEmployee = function () {
        $scope.YearCheckCount = 0;
        $http({
            method: 'POST',
            url: '../OHS/GetNeedCheckEmployee'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.YearCheckCount = ret.Data;
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetNeedCheckEmployeeList = function () {

        if ($scope.YearCheckList == null) {
            $scope.LoadData = true;
            $http({
                method: 'POST',
                url: '../OHS/GetNeedCheckEmployeeList'
            })
                .success(function (ret) {
                    common.success($scope, null, ret);
                    $scope.LoadData = false;
                    if (ret.Code == 100) {
                        $scope.YearCheckList = ret.Data;
                    } else
                        alertify.alert(ret.Msg);

                })
                .error(function (data, status, headers, config) {
                });
        }
    }

    $scope.GetReCheckEmployee = function () {
        $scope.ReCheckCount = 0;
        $http({
            method: 'POST',
            url: '../OHS/GetReCheckEmployee'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ReCheckCount = ret.Data.length;
                    $scope.ReCheckList = ret.Data;
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetYearsReCheckEmployee = function () {
        $scope.YearsReCheckCount = 0;
        $http({
            method: 'POST',
            url: '../OHS/GetYearsReCheckEmployee'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.YearsReCheckCount = ret.Data.length;
                    $scope.YearsReCheckList = ret.Data;
                    $scope.DataLoading = false;
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetCheckYearsCount = function (model) {
        $scope.YearList = [];
        $http({
            method: 'POST',
            url: '../OHS/GetCheckYearsCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        $scope.YearList.push(datalist[i].CheckYear);
                        namelist.push(datalist[i].CheckYear);
                        valuelist.push(datalist[i].Times);
                    }
                    $scope.YearList = $scope.YearList.reverse();
                    var myChart = echarts.init(document.getElementById('yearscheck'));
                    var option = {
                        legend: { show: false },
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(85, 186,223, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 40,
                            right: 25
                        },

                        series: [
                            {
                                name: '体检人次',
                                type: 'bar',
                                stack: "task",
                                itemStyle: {
                                    color: 'rgba(85, 186,223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(85, 186,223)",

                                },
                                data: valuelist
                            }

                        ], dataZoom: [{
                            // start: 0,//默认为0
                            // end: 100,//默认为100
                            type: 'slider',
                            show: true,
                            // xAxisIndex: [0],
                            handleSize: 0,//滑动条的 左右2个滑动条的大小
                            startValue: 0, // 初始显示值
                            endValue: 20, // 结束显示值
                            height: 20,//组件高度
                            left: '1%', //左边的距离
                            right: '1%',//右边的距离
                            bottom: -15,//底边的距离
                            // borderColor: "#000",
                            fillerColor: 'grey',
                            borderRadius: 5,
                            backgroundColor: '#eee',//两边未选中的滑动条区域的颜色
                            showDataShadow: false,//是否显示数据阴影 默认auto
                            showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
                            realtime: true, //是否实时更新
                            filterMode: 'filter',
                        }]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GetCheckResultChart = function (year) {
        $http({
            method: 'POST',
            url: '../OHS/GetCheckResultChart',
            data: { 'Year': 2015 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var datasource = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var obj = {
                            'name': datalist[i].Name,
                            'value': datalist[i].Count
                        };
                        datasource.push(obj);
                    }
                    var myChart = echarts.init(document.getElementById('resultchart'));
                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                center: ['60%', '60%'],
                                name: '结果类型',
                                type: 'pie',
                                radius: '50%',
                                data: datasource,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option, true);

                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }


    $scope.GetCheckTypeChart = function (year) {
        $http({
            method: 'POST',
            url: '../OHS/GetCheckTypeChart',
            data: { 'Year': 2015 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var datasource = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var obj = {
                            'name': datalist[i].Name,
                            'value': datalist[i].Count
                        };
                        datasource.push(obj);
                    }
                    var myChart = echarts.init(document.getElementById('typechart'));
                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                center: ['60%', '60%'],
                                name: '检查类型',
                                type: 'pie',
                                radius: '50%',
                                data: datasource,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option, true);

                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }

    $scope.GetCheckRateChart = function () {
        var myChart = echarts.init(document.getElementById('checkratechart'));

        const gaugeData = [
            {
                value: 82,
                name: '',
                title: {
                    offsetCenter: ['0%', '-30%']
                },
                detail: {
                    valueAnimation: true,
                    offsetCenter: ['0%', '0%']
                }
            }
        ];

        var option = {
            series: [
                {
                    type: 'gauge',
                    startAngle: 90,
                    endAngle: -270,
                    pointer: {
                        show: false
                    },
                    progress: {
                        show: true,
                        overlap: false,
                        roundCap: true,
                        clip: false,
                        itemStyle: {
                            borderWidth: 1,
                            borderColor: '#464646'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            width: 40
                        }
                    },
                    splitLine: {
                        show: false,
                        distance: 0,
                        length: 10
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        show: false,
                        distance: 50
                    },
                    data: gaugeData,
                    title: {
                        fontSize: 14
                    },
                    detail: {
                        width: 50,
                        height: 14,
                        fontSize: 24,
                        color: 'inherit',
                        borderColor: 'inherit',
                        borderRadius: 20,
                        borderWidth: 0,
                        formatter: '{value}%'
                    }
                }
            ]
        };
        myChart.setOption(option, true);
    }

    $scope.ShareWin = function (model) {
        $scope.UserDetail = model;
        $scope.BindDepartmentsList("deplist", $scope.UserDetail.OHSDepartmentList);
        $scope.BindWorkSpacesList("workspacelist", $scope.UserDetail.OHSWSList);
    }

    $scope.SaveOHSAdmin = function (model,searchmodel,page) {
        var deplist = $("#deplist").val();
        var wspacelist = $("#workspacelist").val();
        $http({
            method: 'POST',
            url: '../OHS/AddUserPlace',
            data: { 'UserNo': model.UserNo, 'DepartmentList': deplist, 'WorkSpaceList': wspacelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    $scope.GetUserPageList(searchmodel, page);
                    document.getElementById("btn_close").click();
                } else
                    alertify.alert(ret.Msg);

            })
            .error(function (data, status, headers, config) {
            });
    }

});

app.filter("JSONDate", function ($filter) {
    return function (input, format) {
        if (input) {
            var r = input.replace(/[^0-9|-]+/g, '');
            var timestamp = Number(r);
            return $filter("date")(timestamp, format);
        }
        else {
            return input;
        }
    }
});